import {
  GET_DATA,
  GET_DATA_SUCCESS,
  GET_DATA_FAIL,
  SET_IP,
  SET_RECEIVE_URL,
  SET_REMIND_PHONE,
  SET_REMIND_VALUE,
  UPDATE_DATA,
  UPDATE_DATA_SUCCESS,
  UPDATE_DATA_FAIL,
} from '@/actions/individuationSetting'

const initState = {
  account: '',
  smsNum: '',
  ip: '',
  receiveUrl: '',
  remindPhone: '',
  remindValue: '',
  saveButtonLoading: false,
}

export default function individuationSettingReducer(state = initState, action) {
  switch (action.type) {
    case GET_DATA_SUCCESS:
      const { account, smsNum, ip, receiveUrl, remindPhone, remindValue } = action.data
      return { ...state, account, smsNum, ip, receiveUrl, remindPhone, remindValue }
      break;

    case SET_IP:
      return { ...state, ip: action.ip }
      break;

    case SET_RECEIVE_URL:
      return { ...state, receiveUrl: action.receiveUrl }
      break;

    case SET_REMIND_PHONE:
      return { ...state, remindPhone: action.remindPhone }
      break;

    case SET_REMIND_VALUE:
      return {...state, remindValue: action.remindValue }
      break;

    case UPDATE_DATA:
      return { ...state, saveButtonLoading: true }
      break;

    case UPDATE_DATA_SUCCESS:
    case UPDATE_DATA_FAIL:
      return { ...state, saveButtonLoading: false}
      break
  
    default:
      return state
      break;
  }
}